package com.tiance.demo.service.mysql.analyzer.pageindex;

import com.tiance.demo.service.mysql.utils.ByteUtils;
import com.tiance.demo.service.mysql.bo.pageindex.RecordHead;
import com.tiance.demo.service.mysql.bo.pageindex.Supremum;

public class SupremumAnalyzer {
    public static Supremum analyse(byte[] bytes) {
        Supremum supremum = new Supremum();
        supremum.setBytes(bytes);

        byte[] recordHeadBytes = new byte[RecordHead.SIZE];
        System.arraycopy(bytes, 0, recordHeadBytes, 0, RecordHead.SIZE);
        RecordHead recordHead = RecordHeadAnalyzer.analyse(recordHeadBytes);
        supremum.setRecordHead(recordHead);

        analyseMark(supremum);

        return supremum;
    }

    private static void analyseMark(Supremum supremum) {
        byte[] bytes = new byte[8];
        System.arraycopy(supremum.getBytes(), 5, bytes, 0, 8);

        String mark = ByteUtils.bytesToASCIIStr(bytes);
        supremum.setMark(mark);
    }
}
